<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>诊疗开方</title>
    <link rel="stylesheet" href="../../lib/layui/css/layui.css"/>
    <script src="../../lib/layui/layui.js"></script>
    <script src="../../js/jquery.min.js"></script>
    <script type="text/javascript" src="../../js/xadmin.js"></script>
    <script src="../../js/common.js"></script>
</head>
<body>
<div class="x-nav">
			<span class="layui-breadcrumb">
				<a href="">首页</a>
				<a>
					<cite>诊疗开方 / Clinical prescribing</cite></a>
			</span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:0px;float:right"
       onclick="location.reload()"
       title="刷新">
        <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i></a>
</div>
<!-- 左侧数据表格 -->
<div class="layui-col-md2">
    <table class="layui-table" id="waitPatient">
    <div>
        <tr id="1">
            <th class="layui-bg-green">今日待诊
                    <a class="layui-btn layui-btn-small layui-inline" style="line-height:0px;float:right" onclick="location.reload()" title="刷新">
                <i class="layui-icon layui-icon-refresh" style="line-height:20px"></i></a></th>
        </tr>
    </div>
    <div>
        <tr id="2">
            <th class="layui-bg-green">今日已诊</th>
        </tr>
    </div>
    </table>
</div>

<!-- 显示患者信息 -->
<div><br/>
    <div class="layui-col-md6" id="info"><h3><strong>当前患者信息</strong></h3>
        <span id="r1_rNumber">{{挂号单号}}</span>&nbsp;&nbsp;&nbsp;
        <span id="r1_name">{{姓名}}</span>&nbsp;&nbsp;&nbsp;
        <span id="r1_gender">{{性别}}</span>&nbsp;&nbsp;&nbsp;
        <span id="r1_age">{{年龄}}</span>&nbsp;&nbsp;&nbsp;
    </div>
    <div class="layui-col-md4">
        <button type="button" onclick="xadmin.open('导入患者病例模板','2.2.6.html',600,400)" class="layui-btn layui-btn-lg layui-btn-radius layui-btn-normal">查看历史病例</button>
        <button type="button" onclick="confirmTrans()" class="layui-btn layui-btn-lg layui-btn-radius layui-btn-normal">完成此次就诊</button>
    </div>
</div>
<!-- 选项卡 -->
<div class="layui-col-md8">
    <div class="layui-tab layui-tab-card" lay-filter="select">
        <ul class="layui-tab-title">
            <li class="layui-this">患者病历</li>
            <li>临床诊断</li>
            <li>中药处方</li>
            <li>中成药处方</li>
            <li>西药处方</li>
            <li>检查</li>
            <li>其他费用</li>
            <li>常用模板导入</li>
        </ul>
        <!-- 每个选项卡的内容 -->
        <div class="layui-tab-content" >
            <!-- 选项卡第一部分 患者病例-->
            <div class="layui-tab-item layui-show">
                <!-- 患者病历 -->
                <button class="layui-btn" onclick="xadmin.open('导入患者病例模板','2.2.2.html',600,600)"><i
                        class="layui-icon"></i>导入病例模板
                </button>
                <form class="layui-form layui-form-pane" lay-filter="form_1" id="form_1" action="">
                    <div class="layui-form-item layui-form-text">
                        <label class="layui-form-label">患者主述</label>
                        <div class="layui-input-block">
                            <textarea lay-verify="required" id="pStatement" placeholder="请输入患者对病情的描述" class="layui-textarea" name="pStatement"></textarea>
                            <!--  当前患者的id 和名字 挂号单id，当前登录人的token  -->
                            <textarea id="r1_id" class="layui-hide" name="pId">0</textarea>
                            <textarea id="r1_name2" class="layui-hide" name="pName">null</textarea>
                            <textarea id="rId" class="layui-hide" name="rId">0</textarea>
                            <textarea id="token" class="layui-hide" name="token">null</textarea>
                        </div>
                    </div>
                    <div class="layui-form-item layui-form-text">
                        <label class="layui-form-label">过往病症</label>
                        <div class="layui-input-block">
                            <textarea lay-verify="required" lay-reqText="若没有请填写：无过往病症史" placeholder="请输入患者过往的病症史" class="layui-textarea" id="pPastIllness" name="pPastIllness"></textarea>
                        </div>
                    </div>
                    <div class="layui-form-item layui-form-text">
                        <label class="layui-form-label">身体检查</label>
                        <div class="layui-input-block">
                            <textarea lay-verify="required" placeholder="请输入当前对患者进行检查的情况" class="layui-textarea" id="pExamination" name="pExamination"></textarea>
                        </div>
                    </div>
                   <div class="layui-form-item layui-form-text">
                        <label class="layui-form-label">辅助检查</label>
                        <div class="layui-input-block">
                            <textarea lay-verify="required" placeholder="请输入患者当前辅助检查的情况" class="layui-textarea" id="pAuxiliary" name="pAuxiliary"></textarea>
                        </div>
                    </div>
                    <div class="layui-form-item layui-form-text">
                        <label class="layui-form-label">治疗建议</label>
                        <div class="layui-input-block">
                            <textarea placeholder="请输入您的治疗建议" class="layui-textarea" id="pIdea" name="pIdea"></textarea>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-input-block">
                            <button type="submit" class="layui-btn" lay-submit="" lay-filter="form1">保存</button>
                            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                        </div>
                    </div>
                </form>
            </div>

            <!-- 选项卡第二部分 临床诊断-->
            <div class="layui-tab-item">
                <div class="layui-card-header">
                    <button class="layui-btn" onclick=layerTest()>
                        <i class="layui-icon"></i>添加其他病症
                    </button>
                </div>
                <!-- 穿梭框 -->
                <div id="test11" class="demo-transfer"></div>
                <div class="layui-input-block">
                    <button type="button" class="layui-btn" lay-demotransferactive="getData1">保存</button>
                </div>
            </div>

            <!-- 选项卡第三部分 中药处方-->
            <div class="layui-tab-item" >
                <!-- 添加一个可添加删除式的选项卡，每次添加都加载一个调理方的引擎模板 -->
                <div class="site-demo-button" style="margin-bottom: 0;">
                    <button class="layui-btn site-demo-active" data-type="tabAdd">新增调理方</button>
                </div>
                <div class="layui-tab" lay-filter="demo" lay-allowclose="true">
                    <ul class="layui-tab-title" id="chufangName">
                        <li class="layui-this" lay-id="1">调理方1</li>
                    </ul>
                    <div class="layui-tab-content" style="height: 530px;">
                        <div class="layui-tab-item layui-show">
                            <form class="layui-form layui-form-pane" lay-filter="form_2" action="">
                                <div class="layui-form-item">
                                    <label class="layui-form-label">添加药品</label>
                                    <div class="layui-input-inline" >
                                        <select name="drId"  lay-verify="required" lay-search="" >
                                            <option value="0" id="search" >直接选择或搜索选择</option>

                                        </select>
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <label class="layui-form-label">药品类型</label>
                                    <div class="layui-input-block">
                                        <input type="radio" name="drType" value="11" title="颗粒" checked="">
                                        <input type="radio" name="drType" value="10" title="袋装颗粒">
                                        <input type="radio" name="drType" value="12" title="饮片">
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <label class="layui-form-label">服用方式</label>
                                    <div class="layui-input-block">
                                        <input type="radio" name="preTakeType" value="37" title="口服" checked="">
                                        <input type="radio" name="preTakeType" value="38" title="外用">
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <label class="layui-form-label">用量</label>
                                    <div class="layui-input-inline">
                                        <input type="text" name="dr_consumption_day" lay-verify="required" placeholder="请输入每日服药次数"
                                               autocomplete="off" class="layui-input">
                                    </div>
                                    <div class="layui-input-inline">
                                        <input type="text" name="dr_consumption_times" lay-verify="required"
                                               placeholder="请输入每次服药几副" autocomplete="off" class="layui-input">
                                    </div>
                                </div>
                                <div class="layui-form-item layui-form-text">
                                    <label class="layui-form-label" style="width: 500px;">给药房的备注</label>
                                    <div class="layui-input-block" style="width: 500px;">
                                        <textarea placeholder="备注" class="layui-textarea" name="preRemarks"></textarea>
                                    </div>
                                </div>
                                <div class="layui-form-item layui-form-text">
                                    <label class="layui-form-label" style="width: 500px;">医嘱<button onclick="xadmin.open('导入患者病例模板','2.2.3.html',600,600)" type="button" class="layui-btn layui-btn-sm  layui-btn-radius" style="float:right">导入医嘱模板</button></label>
                                    <div class="layui-input-block" style="width: 500px;">
                                        <textarea placeholder="医嘱" class="layui-textarea" name="doctor_word"></textarea>
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <div class="layui-input-block">
                                        <button type="submit" class="layui-btn" lay-submit="" lay-filter="demo1">保存
                                        </button>
                                        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>

            </div>
            <!-- 选项卡第四部分 中成药处方 -->
            <div class="layui-tab-item">
            <!-- 穿梭框 -->
                <div id="TCM" class="demo-transfer"></div>
                <div class="layui-input-block">
                    <button type="button" class="layui-btn" lay-CTMtransferactive="getData2">保存</button>
                </div>
            </div>
            <!-- 选项卡第五部分 西药处方-->
            <div class="layui-tab-item">
                <div id="Wm" class="demo-transfer"></div>
                <div class="layui-input-block">
                    <button type="button" class="layui-btn" lay-Wmtransferactive="getData3">保存</button>
                </div>
            </div>
            <!-- 选项卡第六部分 体检项目-->
            <div class="layui-tab-item">
                <div id="physicalExamination" class="demo-transfer"></div>
                <div class="layui-input-block">
                    <button type="button" class="layui-btn" lay-PEtransferactive="getData4">保存</button>
                </div>
            </div>
            <!-- 选项卡第七部分 其他费用-->
            <div class="layui-tab-item">
                <div id="Otherprice" class="demo-transfer" ></div>
                <div class="layui-input-block">
                    <button type="button"  class="layui-btn" lay-Otherprice="getData5" >保存</button>
                </div>
            </div>
            <!-- 选项卡第八部分 常用模板导入-->
            <div class="layui-tab-item">
                <button type="button" onclick="xadmin.open('导入患者病例模板','2.2.4.html',600,600)"  class="layui-btn"  >院内协定方</button>
                <button type="button" onclick="xadmin.open('导入患者病例模板','2.2.5.html',600,600)"  class="layui-btn"  >调理方</button>
                <div id="view4"></div>
                <div id="view5"></div>
            </div>
        </div>
    </div>
</div>
</body>
</html>
<!-- 正在等待的患者表格 -->
<script>
$(function(){
    //发送ajax请求获取患者未诊治的挂号单信息
        useAjax("/JT90/selectRegister", null, "JSON", "GET", function (map) {
            if (map.success) {
                //拼接数据  <tr><td><a href="#">{{pName}}</a></td></tr>
                //未诊治
                $("#1~tr[class='add']").remove();
                $.each(map.result2, function (index, item) {
                    $('#1').after("<tr class='add'><td><a href='#' id="+item.registrationNumber+" onclick='r_info(this.id)'>"+item.pName2+"</a></td></tr>");

                    if (index==0){
                        //输出第一个人的信息
                        $('#r1_rNumber').html("挂号单号："+item.registrationNumber);
                        $('#r1_name').html("姓名："+item.pName2);
                        $('#r1_gender').html("性别："+item.pGender2);
                        $('#r1_age').html("年龄："+item.pAge2);
                        $('#r1_id').html(item.pId); //用于在form表单里存放信息
                        $('#r1_name2').html(item.pName2); //用于在form表单里存放信息
                        $('#rId').html(item.rId); //用于在form表单里存放信息
                    }
                });
                //已诊治
                $('#2~tr[class=\'add\']').remove();
                $.each(map.result, function (index, item) {
                    $('#2').after("<tr><td>"+item.pName2+"</td></tr>");
                });
            }
        })
    //获取当前登录的用户token
    getToken();
})

    //获取当前登录的用户token
    function getToken(){
        var token = sessionStorage.getItem("token");
        $("#token").html(token);
    }

       //单击触发方法，显示该患者信息   根据挂号单号作为唯一的依据进行查询
       function r_info(id){
           useAjax("/JT90/r_info",{"id":id},"JSON","GET",function(map){
               var data = map.result;
               $('#r1_rNumber').html("挂号单号："+data.registrationNumber);
               $('#r1_name').html("姓名："+data.pName2);
               $('#r1_gender').html("性别："+data.pGender2);
               $('#r1_age').html("年龄："+data.pAge2);

               $('#r1_id').html(data.pId);       //修改form表单的信息
               $('#r1_name2').html(data.pName2); //修改form表单的信息
               $('#rId').html(data.rId); //用于在form表单里存放信息
           })
       }
</script>

<!--患者病例-->
<script>
    var totalSubmit=0;
    //提交form表单
    layui.use(['form','layer'], function(){
        var form = layui.form,
            layer=layui.layer;

        //监听提交
        form.on('submit(form1)', function(data){

            //发送ajax  form表单数据里面有当前患者的id
            useAjax("/JT90/PCH",data.field,"JSON","GET",function(count){
                    //输出提示信息
                   if (count==1){
                       layer.msg("保存成功");
                       totalSubmit=1;
                   }else if (count==2){
                       layer.msg("未获取到当前患者信息");
                   }else if (count==3){
                       layer.msg("当前用户未登录");
                   }else{
                       layer.msg("保存失败");
                   }
                //执行重置清空内容
                $("#form_1")[0].reset();
                layui.form.render();
            })
            return false;
        });
    })

    //导入病历模板
    layui.use(['form','layer'], function(){
        var form = layui.form,
            layer=layui.layer;

        getChildrenData=function (id) {
            if (id!=null){
                useAjax("/JT90/getTemplateByid",{"id":id},"JSON","GET",function(map){
                    var data = map.data;
                    form.val("form_1", { //formTest 即 class="layui-form" 所在元素属性 lay-filter="" 对应的值
                        "pStatement": data.p_statement // "name": "value"
                        ,"pPastIllness": data.p_past_illness
                        ,"pExamination": data.p_examination
                        ,"pAuxiliary": data.p_auxiliary
                        ,"pIdea": data.p_idea
                    });
                    form.render();
                })
            }
        }
    })
</script>
<!-- 临床诊断 -->
<script>
    var oldCase= 0;
    layui.use(['transfer', 'layer', 'util', 'element'], function () {
        var $ = layui.$,
            transfer = layui.transfer,
            layer = layui.layer,
            util = layui.util;

        //获取useAjax返回的数据，给其他方法用
        var list;
        //发送ajax请求获取病症表(disease_tcm)全部数据，返回数据有规定格式
       var useajax = useAjax("/JT90/selectDT",null,"JSON","GET",function(map){
             list = map.result;
            transfer.render({
                elem: '#test11',
                data: list,
                title: ['病症','已添加的病症'],
                showSearch: true,
                height: 400,
                id:'Shuttle1',
                parseData: function(list){
                    return {
                        "value": list.diseaseId //数据值
                        ,"title": list.diseaseName //数据标题
                    }
                }
            })
        })

        //获取穿梭框右边的数据
        util.event('lay-demotransferactive', {
            getData1: function(othis){
                var getData = transfer.getData('Shuttle1'); //获取右侧数据
                if (getData!=""&&getData!=null){
                    var dat = JSON.stringify(getData);
                    //发送ajax将数据给后台
                    useAjax("/JT90/addclinicalCiagnosis",dat,"JSON","POST",function(map){
                        if(map.success){
                            oldCase=1;
                            layer.alert(map.message);
                        }else{
                            layer.alert("程序异常");
                        }
                    })
                }else{
                    layer.alert("中成药保存内容为空，保存失败");
                }

            }
        });

    })
    //添加新病症
    function layerTest(){
        layer.prompt({
            formType: 0,
            value: '',
            title: '请输入需要添加的病症',
            btn: ['确定','取消'], //按钮，
            btnAlign: 'c'
        }, function(value, index, elem){
            useAjax("/JT90/addDisease",{"value":value},"JSON","GET",function(map){
               if(map.success==true){
                   layer.msg(map.message);
                   //关闭弹窗
                   layer.close(index);
               }else{
                   layer.msg(map.message);
                   //关闭弹窗
                   layer.close(index);
               }

            })
        });
    }
</script>
<!-- 中药处方 -->
<script>
    //新增选项卡
    var nameId = 2; //设置添加选项卡时，选项卡名字后数字初始值
    layui.use(['element', 'form', 'layedit', 'laydate', 'laytpl','layer'], function () {
        var $ = layui.jquery,
            element = layui.element, //Tab的切换功能，切换事件监听等，需要依赖element模块
            form=layui.form,
            layer = layui.layer,
            layedit = layui.layedit,
            laydate = layui.laydate,
            laytpl = layui.laytpl;

        //触发事件
        var active = {
            tabAdd: function (getTpl) {
                //新增一个Tab项
                element.tabAdd('demo', {
                    title: '调理方' + nameId,
                    content: '<div style="height: 430px;" ><iframe scrolling="auto" frameborder="0" src="2.2.1.html" width="100%" height="99%"></iframe></div>',
                    id: nameId
                })
                nameId++; //数字+1
            }
        };
        $('.site-demo-active').on('click', function () {
            var othis = $(this),
                type = othis.data('type');
            active[type] ? active[type].call(this, othis) : '';
        });


        //form表单 监听提交
        form.on('submit(demo1)', function (data) {
            useAjax("/JT90/addPOTCM",data.field,"JSON","GET",function(map){
                layer.msg(map.message);
            })
            return false;
        });

        //监听中药处方的tab的删除
        element.on('tabDelete(demo)', function(data){
            useAjax("/JT90/addPOTCM",{"del":data.index},"JSON","GET",function(map){
                layer.msg(map.message);
            })
        });


        //监听选项卡的切换,下拉列表追加药品
        element.on('tab(select)', function(data){
            //得到当前Tab的所在下标 data.index
            $('#search~option').remove();   //删除原有的下拉列表
            if (data.index==2){
                useAjax("/JT90/selectDrugsName",null,"JSON","GET",function(data){
                    //追加标签 new Option(item.drName,item.drId)
                    $.each(data.data, function (index, item) {
                        $('#search').after("<option value='"+item.drId+"'>"+item.drName+"</option>");
                    });
                    form.render();
                })
            }
        });

        //导入医嘱模板  接收到的数据是医嘱的内容
        doctorWord = function (data){
            //变更为当前选择的模板内容
            form.val("form_2", { //formTest 即 class="layui-form" 所在元素属性 lay-filter="" 对应的值
                "doctor_word": data // "name": "value"
            });
            form.render();
        }


    });
</script>
<!--中成药处方-->
<script>
    layui.use(['transfer', 'layer', 'util', 'table'], function () {
        var $ = layui.$
            , transfer = layui.transfer
            , layer = layui.layer
            , util = layui.util
            , table = layui.table;
        //ajax查询中成药数据 Chinese traditional medicine
        useAjax("/JT90/CTM",null,"JSON","GET",function(map){
            //将返回的数据放到穿梭框
            list = map.list;
            transfer.render({
                elem: '#TCM'
                , data: list
                , title: ['中成药', '已添加的中成药品']
                , showSearch: true
                , height: 400
                , id: 'Drugs'
                ,parseData: function(list){
                    return {
                        "value": list.drId //数据值
                        ,"title": list.drName //数据标题
                    }
                }
            })
        })

        //获取穿梭框右边的数据
        util.event('lay-CTMtransferactive', {
            getData2: function(othis){
                var getData = transfer.getData('Drugs'); //获取右侧数据
                if (getData!=""&&getData!=null){
                    var dat = JSON.stringify(getData);
                    //发送ajax将数据给后台
                    useAjax("/JT90/getCTM",dat,"JSON","POST",function(map){
                        if(map.success){
                            layer.alert(map.message);
                        }else{
                            layer.alert("程序异常");
                        }
                    })
                }else{
                    layer.alert("中成药保存内容为空，保存失败");
                }

            }
        });

    })
</script>
<!-- 西药处方 -->
<script>
    layui.use(['transfer', 'layer', 'util', 'table'], function () {
        var $ = layui.$
            , transfer = layui.transfer
            , layer = layui.layer
            , util = layui.util
            , table = layui.table;
        //ajax查询西药数据  Western medicine
        useAjax("/JT90/selectWm",null,"JSON","GET",function(map){
            //将返回的数据放到穿梭框
            list = map.date;
            transfer.render({
                elem: '#Wm'
                , data: list
                , title: ['西药','已添加的西药']
                , showSearch: true
                , height: 400
                , id: 'Wm'
                ,parseData: function(list){
                    return {
                        "value": list.drId //数据值
                        ,"title": list.drName //数据标题
                    }
                }
            })
        })

        //获取穿梭框右边的数据
        util.event('lay-Wmtransferactive', {
            getData3: function(othis){
                var getData = transfer.getData('Wm'); //获取右侧数据
                if (getData!=""&&getData!=null){
                    var dat = JSON.stringify(getData);
                    //发送ajax将数据给后台
                    useAjax("/JT90/getWm",dat,"JSON","POST",function(map){
                        if(map.success){
                            layer.alert(map.message);
                        }else{
                            layer.alert("程序异常");
                        }
                    })
                }else{
                    layer.alert("西药保存内容为空，保存失败");
                }
            }
        });

    })
</script>
<!-- 检查 -->
<script>
    layui.use(['transfer', 'layer', 'util', 'table'], function () {
        var $ = layui.$
            , transfer = layui.transfer
            , layer = layui.layer
            , util = layui.util
            , table = layui.table;
        //ajax查询体检项目数据  physical_examination
        useAjax("/JT90/selectPE",null,"JSON","GET",function(map){
            //将返回的数据放到穿梭框
            list = map.date;
            transfer.render({
                elem: '#physicalExamination'
                , data: list
                , title: ['体检项目','已添加的选项']
                , showSearch: true
                , height: 400
                , id: 'PE'
                ,parseData: function(list){
                    return {
                        "value": list.id //数据值
                        ,"title": list.p_projectName //数据标题
                    }
                }
            })
        })

        //获取穿梭框右边的数据
        util.event('lay-PEtransferactive', {
            getData4: function(othis){
                var getData = transfer.getData('PE'); //获取右侧数据
                if (getData!=""&&getData!=null){
                    var dat = JSON.stringify(getData);
                    //发送ajax将数据给后台
                    useAjax("/JT90/getPE",dat,"JSON","POST",function(map){
                        if(map.success){
                            layer.alert(map.message);
                        }else{
                            layer.alert("程序异常");
                        }
                    })
                }else{
                    layer.alert("体检项目保存内容为空，保存失败");
                }
            }
        });
    })
</script>
<!-- 其他费用 -->
<script>
    layui.use(['transfer', 'layer', 'util', 'table'], function () {
        var $ = layui.$
            , transfer = layui.transfer
            , layer = layui.layer
            , util = layui.util
            , table = layui.table;
        //ajax查询其他费用表的数据
        useAjax("/JT90/selectOP",null,"JSON","GET",function(map){
            //将返回的数据放到穿梭框
            list = map.date;
            transfer.render({
                elem: '#Otherprice'
                , data: list
                , title: ['其他费用','已添加的选项']
                , showSearch: true
                , height: 400
                , id: 'OP'
                ,parseData: function(list){
                    return {
                        "value": list.id //数据值
                        ,"title": list.o_priceName  //数据标题
                    }
                }
            })
        })

        //获取穿梭框右边的数据
        util.event('lay-Otherprice', {
            getData5: function(othis){
                var getData = transfer.getData('OP'); //获取右侧数据
                if (getData!=""&&getData!=null){
                    var dat = JSON.stringify(getData);
                    //发送ajax将数据给后台
                    useAjax("/JT90/getOP",dat,"JSON","POST",function(map){
                        if(map.success){
                            layer.alert(map.message);
                        }else{
                            layer.alert("程序异常");
                        }
                    })
                }else{
                    layer.alert("费用项目保存内容为空，保存失败");
                }
            }
        });

    })
</script>
<!--院内协定方模板引擎-->
<script id="AgreementPartyTemplate" type="text/html">
    <div class="layui-card layui-anim layui-anim-upbit" id="{{d.id}}">
        <div class="layui-card-header">{{d.t_name}}<button onclick=removeTemplate("{{d.id}}") type="button" class="layui-btn layui-btn-sm  layui-btn-radius" style="float:right">移除模板</button></div>
        <div class="layui-card-body">
            <ul>
                <li>功效:{{d.t_effect}}</li>
                <li>用法:{{d.usage_name}}</li>
                <li>药品:{{d.dr_name}}</li>
            </ul>
        </div>
    </div>
</script>
<!--调理方模板引擎-->
<script id=Organize" type="text/html">
    <div class="layui-card layui-anim layui-anim-upbit">
        <div class="layui-card-header">{{d.t_name}}<button onclick=removeTemplate("{{d.id}}") type="button" class="layui-btn layui-btn-sm  layui-btn-radius" style="float:right">移除模板</button></div>
        <div class="layui-card-body">
            <ul>
                <li>功效:{{d.t_effect}}</li>
                <li>说明:{{d.t_explain}}</li>
                <li>药品:{{d.dr_name}}</li>
            </ul>
        </div>
    </div>
</script>
<!--常用模板导入-->
<script>
    //设置接收数据的数据
    var arrayData = new Array();

    //院内协定方获取传来的id
    getId =function (data){
        if (data.tem==4){
            //根据id去查询模板数据追加在指定标签下
            useAjax("/JT90/getAgreementPartyTemplateById",{"id":data.id},"JSON","GET",function (map) {
                var data = map.data;
                arrayData.push(data);
                //给院内协定方模板添加数据
                layui.use("laytpl",function() {
                    var laytpl=layui.laytpl;
                    var getTpl = $("#AgreementPartyTemplate").html();	    //获取页面的js模板
                    laytpl(getTpl).render(data, function (html) {
                        $("#view4").append(html);	          //添加新的数据
                    });
                })
            })
        }else{
            //根据id去查询模板数据追加在指定标签下
            useAjax("/JT90/getOrganize",{"id":data.id},"JSON","GET",function (map) {
                var data = map.data;
                arrayData.push(data);
                //给调理方模板添加数据
                var tpl = layui.laytpl;
                var getTpl = $("#AgreementPartyTemplate").html();	    //获取页面的js模板
                tpl(getTpl).render(data, function (html) {
                    $("#view5").append(html);	          //添加新的数据
                });
            })
        }
    }

    //移除加载的模板的方法
    removeTemplate =function (data){
        $("div[id="+data+"]").remove();
    }

</script>
<!--查看历史病例-->
<script>
   getOldCaseId = function(){
       //获取当前患者id
       var id =$("#r1_id").html();
       return id;
   }
</script>
<!--总提交-->
<script>
    var confirmTrans= function(){
        if (totalSubmit==0||oldCase==0){
            layer.msg("未保存患者病例信息或病症未保存");
        }else{
            totalSubmit=0;
            oldCase=0;
            layer.open({
                content: '提交后将不能修改,确认提交吗'
                ,btn: ['提交', '取消']
                ,yes: function(index, layero){
                    //获取常用模板导入的数据
                    if (arrayData.length==0){
                        arrayData=null;
                    }
                    //确认提交，发送ajax
                    useAjax("/JT90/submission",JSON.stringify(arrayData),"JSON","POST",function(map){
                        if (map.success){
                            parent.layer.msg(map.message,{time:2000,icon:6},function(){
                                location.reload();
                            });
                        }else{
                            layer.msg(map.message+"提交失败");
                        }
                    })
                    layer.close(index);
                }
                ,btn2: function(index, layero){
                    //取消：关闭弹窗
                    layer.close(index);
                }
            })
        }
    }
</script>
